<!-- Loads initialization file with a couple of variables -->

<%@ include file="../../inc/init.jsp" %>

<html>
	<head>
		<title>
			Graduate Admission System | University of California - San Diego | 
			Country of Residence Page
		</title>
		<link type="text/css" rel="stylesheet" href="<%= BASE %>css/main.css">
		<link type="text/css" rel="stylesheet" href="<%= BASE %>css/expand.css">
	</head>
	<body>
	<div class="header-top"></div>
		<div class="header">
			<a href="<%= BASE %>index.jsp"><img src="<%= BASE %>img/logo.png"></a>
		</div>
		<div class="content">
		<div class="message"></div>
		<%
			try {

			Applicant a = (Applicant)session.getAttribute("applicant");
			
			/**** Get parameters via URL from previous page and store to session object ****/
			
			a.setCountryOfCitizenship(request.getParameter("countryOfCitizenship"));
			a.setCountryOfCitizenshipId(Integer.parseInt(request.getParameter("id")));
			
			session.setAttribute("applicant", a);
		
		%>
		
		<h2>Previous Data:</h2>
		
		<ol class="tree">
			<li><label for="general">General Information</label><input type="checkbox" id="general" />
				<ol> 
					<li>
						<table>
							<tr><td>First Name:</td><td><%= a.getFirstName() %></td></tr>
							<tr><td>Middle Initial:</td><td><%= a.getMiddleInitial() %></td></tr>
							<tr><td>Last Name:</td><td><%= a.getName() %></td></tr>
							<tr><td>Country of Citizenship:</td><td><%= a.getCountryOfCitizenship() %></td></tr>
						</table>
					</li>
				</ol>
			</li>
		</ol>
		<hr>
		<br>
			
			Please select your country of residence from the list bellow.
			
			<br><br> Is your country of citizenship also your country of residence? 
			If yes, please click 
			<a href="address.jsp?countryOfResidence=<%= a.getCountryOfCitizenship() %>
					&id=<%= a.getCountryOfCitizenshipId() %>">here</a>!.
			
			<br><br>
			
			If your country of residence is different than your country of citizenship please select the appropriate from the list bellow.
			
			<br><br>
			
			<%
				/**** Get countries ****/
							
				Location c = new Location();
				ArrayList<Location> cAl = new ArrayList<Location>();	
				cAl = c.getCountries();
							
				/*** Prepare auxiliary iterator 'col' to get a three-column format ***/
					
				int col = cAl.size()/3;
							
				out.print("<table><tr><td>");
						
				/**** Iteration for column one ****/
					
				for(int i=0; i<col; i++)
				{
					out.print("<a href=\"address.jsp" +
							  "?countryOfResidence=" + cAl.get(i).getName() + "&id=" +
							  cAl.get(i).getId() + "\">" + cAl.get(i).getName() + "</a><br>");
				}
						
				out.print("</td><td>");
							
				/**** Iteration for column two ****/
						
				for(int i=col; i<(col+col); i++)
				{
					out.print("<a href=\"address.jsp" +
							  "?countryOfResidence=" + cAl.get(i).getName() + "&id=" +
							  cAl.get(i).getId() + "\">" + cAl.get(i).getName() + "</a><br>");
				}
							
				out.print("</td><td>");
							
				/**** Iteration for column three ****/
						
				for(int i=(col+col); i<cAl.size(); i++)
				{
					out.print("<a href=\"address.jsp" +
							  "?countryOfResidence=" + cAl.get(i).getName() + "&id=" +
							  cAl.get(i).getId() + "\">" + cAl.get(i).getName() + "</a><br>");
				}
							
				out.print("</td></tr></table>");
					
				}
				catch(Exception e)
				{
					response.sendRedirect(BASE + "error.jsp");
				}
			%>
		</div>
	</body>
</html>